﻿@model TestOnlineProject.Models.Entities.QuestionModel
@using TestOnlineProject.Common
@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Create";
}
<script type="text/javascript">
    function check(c, i) {
        $("." + c).attr('checked', false);
        $("#" + i).attr('checked', true);
    }

    tinymce.init({
        menubar: false,
        toolbar: "bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent",
        resize: false,
        statusbar : true,
        height: 150,
        selector : "textarea.mceEditor",
        
    });

    // Change question type.
    $(document).ready(function () {
        // Khong dung Change() duoc.
        $('#QuestionTypeId').live('change', function() {
            var questionTypeId = $(this).val();
            if ($('#section').val() != "") {
                window.location = "@Url.Content("~/Question/Create")?questionTypeId=" + questionTypeId + "&subjectId=" + @ViewBag.Subject.SubjectId + "&sectionId=" + $('#section').val();
            } else {
                window.location = "@Url.Content("~/Question/Create")?questionTypeId=" + questionTypeId + "&subjectId=" + @ViewBag.Subject.SubjectId;
            }
        });
    });

</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject")
    / @Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    /
    @if (@ViewBag.Section != null)
    {
        @Html.ActionLink("Sections", "Index", "Section", new { subjectId = ViewBag.Subject.SubjectId }, new { })
        <span>/</span>
        @Html.ActionLink((string)ViewBag.Section.Name, "Index", "Question", new { subjectId = ViewBag.Subject.SubjectId, sectionId = ViewBag.Section.SectionId }, new { })
    }
    else
    {
        @Html.ActionLink("Questions", "Index", "Question", new { subjectId = (ViewBag.Subject as Subject).SubjectId }, null)
    }
    / Create Question</div>
<br />
<div class="main_nav">
    @if (@ViewBag.Section != null)
    {
        <span><a href="@Url.Content("~/Question/Index")?subjectId=@ViewBag.Subject.SubjectId&sectionId=@ViewBag.Section.SectionId">
            <img src="@Url.Content("~/Images/back button.png")" style="height: 30px"/>
        </a></span>
    }
    else
    {
        <span><a href="@Url.Content("~/Question/Index")?subjectId=@Model.SubjectId">
            <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
        </a></span>
    }
</div>
<br />
<span class="require_info">(*) is required.</span>
@using (Html.BeginForm())
{
    <span class="errorMsg">@Html.ValidationSummary(true)</span>
    @Html.HiddenFor(model => model.QuestionTypeId)
    @Html.HiddenFor(model => model.SubjectId)
    if (@ViewBag.Section != null)
    {
        <input type="hidden" name="section" id="section" value="@ViewBag.Section.SectionId" />
    }
    else
    {
        <input type="hidden" name="section" id="section" value="" />
    }
    <table class="table table-bordered">
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Question Type (*)</span>
            </td>
            <td>
                <span>
                    @Html.DropDownListFor(model => model.QuestionTypeId, ViewBag.QuestionTypeList as SelectList, "Select")
                </span>
            </td>
        </tr>
        @{
            // Single choice.
            if (Model.QuestionTypeId == 1)
            {
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Section</span>
                    </td>
                    <td>
                        @if (@ViewBag.Section != null)
                        {
                            <span>
                                @ViewBag.Section.Name
                            </span>
                        }
                        else
                        {
                            <span>
                                @Html.DropDownListFor(model => model.SectionId, ViewBag.SectionMineList as SelectList)
                            </span>
                        }
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Title (*)</span>
                    </td>
                    <td>
                        <span><span class="errorMsg">@Html.ValidationMessageFor(model => model.Title)</span>
                            @Html.TextBoxFor(model => model.Title, new {style = "width:400px"})
                        </span>
                    </td>
                </tr>
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Question (*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Content)</span>
                        @Html.TextAreaFor(model => model.Content, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>

                for (int i = 0; i < Model.Answers.Count; i++)
                {
                    <tr>
                        <td style="text-align: right">
                            <span>Answer</span>
                            @{
                                int p = i + 1;
                                @(p + " (*)")
                                ;
                            }
                        </td>
                        <td>
                            <span class="errorMsg">@Html.ValidationMessageFor(model => model.Answers[i].Content)</span>
                            @Html.TextAreaFor(model => model.Answers[i].Content, new {style = "width:97%", @class = "mceEditor"})
                            <br />
                            @{

                                var call = "check('class','" + i + "')";
                            }
                            @Html.CheckBoxFor(model => Model.Answers[i].Checked, new {type = "radio", @class = "class", id = i, onclick = @call})
                            <span>Is Correct?</span>
                        </td>
                    </tr>
                }
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" name="submit" value="More Answer" class="btn">
                            More Answer</button>
                        <button type="submit" value="Remove Last Answer" name="submit" class="btn">
                            Remove Last Answer</button>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Explanation</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Explanation)</span>
                        @Html.TextAreaFor(model => model.Explanation, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="Create" name="submit" class="btn" style="width: 80px">Create</button>
                        @if (@ViewBag.Section != null)
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                        }
                        else
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                        }
                    </td>
                </tr>
            }
            // multiple choice.
            if (Model.QuestionTypeId == 2)
            {
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Section</span>
                    </td>
                    <td>
                        @if (@ViewBag.Section != null)
                        {
                            <span>
                                @ViewBag.Section.Name
                            </span>
                        }
                        else
                        {
                            <span>
                                @Html.DropDownListFor(model => model.SectionId, ViewBag.SectionMineList as SelectList)
                            </span>
                        }
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Title (*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Title)</span>
                        @Html.TextBoxFor(model => model.Title, new {style = "width:40%"})
                    </td>
                </tr>
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Question (*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Content)</span>
                        @Html.TextAreaFor(model => model.Content, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>
                for (int i = 0; i < Model.Answers.Count; i++)
                {
                    <tr>
                        <td style="text-align: right">
                            <span>Answer</span>
                            @{
                                int p = i + 1;
                                @(p + " (*)")
                                ;
                            }
                        </td>
                        <td>
                            <span class="errorMsg">@Html.ValidationMessageFor(model => model.Answers[i].Content)</span>
                            @Html.TextAreaFor(model => model.Answers[i].Content, new {style = "width:97%", @class = "mceEditor"})
                            <br />
                            <span class="errorMsg">@Html.ValidationMessageFor(model => model.Answers[i].Grade)</span>
                            <span>Grade: @Html.DropDownListFor(model => model.Answers[i].Grade, (IEnumerable<SelectListItem>) Session["AnswerList" + Model.Answers[i].AnswerId], new {style = "width:90px"})
                                %</span>
                        </td>
                    </tr>
                }
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" name="submit" value="More Answer" class="btn">
                            More Answer</button>
                        <button type="submit" value="Remove Last Answer" name="submit" class="btn">
                            Remove Last Answer</button>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Explanation</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Explanation)</span>
                        @Html.TextAreaFor(model => model.Explanation, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="Create" name="submit" class="btn" style="width: 80px">Create</button>
                        @if (@ViewBag.Section != null)
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                        }
                        else
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                        }
                    </td>
                </tr>
            }
            // mathching.
            if (Model.QuestionTypeId == 3)
            {
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Section</span>
                    </td>
                    <td>
                        @if (@ViewBag.Section != null)
                        {
                            <span>
                                @ViewBag.Section.Name
                            </span>
                        }
                        else
                        {
                            <span>
                                @Html.DropDownListFor(model => model.SectionId, ViewBag.SectionMineList as SelectList)
                            </span>
                        }
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Title (*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Title)</span>
                        @Html.TextBoxFor(model => model.Title, new {style = "width:40%"})
                    </td>
                </tr>
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Question (*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Content)</span>
                        @Html.TextAreaFor(model => model.Content, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>

                for (int i = 0; i < Model.Answers.Count; i++)
                {
                    <tr>
                        <td style="text-align: right">
                            <span>Answer</span>
                            @{
                                int p = i + 1;
                                @(p + " (*)")
                                ;
                            }
                        </td>
                        <td>
                            <span class="errorMsg">@Html.ValidationMessageFor(model => model.Answers[i].Content)</span>
                            @Html.TextAreaFor(model => model.Answers[i].Content, new {style = "width:97%", @class = "mceEditor"})
                            <br />
                            <span class="errorMsg">@Html.ValidationMessageFor(model => model.Matchs[i].Content)</span>
                            @Html.TextBoxFor(model => model.Matchs[i].Content, new {style = "width:400px", placeholder = "Match"})
                        </td>
                    </tr>
                }
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" name="submit" value="More Answer" class="btn">
                            More Answer</button>
                        <button type="submit" value="Remove Last Answer" name="submit" class="btn">
                            Remove Last Answer</button>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Other Invalid Matchs</span>
                    </td>
                    <td>
                        @{
                            if (Model.InvalidMatchs == null || Model.InvalidMatchs.Count == 0)
                            {
                                <span>Empty.</span>
                            }
                            else
                            {
                                for (var i = 0; i < Model.InvalidMatchs.Count; i++)
                                {
                                    <span class="errorMsg">@Html.ValidationMessageFor(model => model.InvalidMatchs[i].Content)</span>
                                    @Html.TextBoxFor(model => model.InvalidMatchs[i].Content, new {style = "width:40%", placeholder = "Match"})
                                    <br />
                                }
                            }
                        }
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" name="submit" value="More Match" class="btn">
                            More Match</button>
                        <button type="submit" value="Remove Last Match" name="submit" class="btn">
                            Remove Last Match</button>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Explanation</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Explanation)</span>
                        @Html.TextAreaFor(model => model.Explanation, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="Create" name="submit" class="btn" style="width: 80px">Create</button>
                        @if (@ViewBag.Section != null)
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                        }
                        else
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                        }
                    </td>
                </tr>
            }
            // true/false.
            if (Model.QuestionTypeId == 4)
            {
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Section</span>
                    </td>
                    <td>
                        @if (@ViewBag.Section != null)
                        {
                            <span>
                                @ViewBag.Section.Name
                            </span>
                        }
                        else
                        {
                            <span>
                                @Html.DropDownListFor(model => model.SectionId, ViewBag.SectionMineList as SelectList)
                            </span>
                        }
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right">
                        <span>Title (*)</span>
                    </td>
                    <td>
                        <span><span class="errorMsg">@Html.ValidationMessageFor(model => model.Title)</span>
                            @Html.TextBoxFor(model => model.Title, new {style = "width:40%"})
                        </span>
                    </td>
                </tr>
                <tr>
                    <td style="width: 150px; text-align: right">
                        <span>Question (*)</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Content)</span>
                        @Html.TextAreaFor(model => model.Content, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>
                for (int i = 0; i < Model.Answers.Count; i++)
                {
                    <tr>
                        <td style="text-align: right">
                            <span>Answer</span>
                            @{
                                int p = i + 1;
                                @p
                                ;
                            }
                        </td>
                        <td>
                            @{

                                var call = "check('class','" + i + "')";
                            }
                            @Html.CheckBoxFor(model => Model.Answers[i].Checked, new {type = "radio", @class = "class", id = i, onclick = @call})
                            @Html.DisplayFor(model => model.Answers[i].Content, new {style = "width:97%"})
                            @Html.HiddenFor(model => model.Answers[i].Content)
                        </td>
                    </tr>
                }
                <tr>
                    <td style="text-align: right">
                        <span>Explanation</span>
                    </td>
                    <td>
                        <span class="errorMsg">@Html.ValidationMessageFor(model => model.Explanation)</span>
                        @Html.TextAreaFor(model => model.Explanation, new {style = "width:97%", @class = "mceEditor"})
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="Create" name="submit" class="btn" style="width: 80px">
                            Create</button>
                        @if (@ViewBag.Section != null)
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId, sectionId = @ViewBag.Section.SectionId }, new { style = "width: 54px", @class = "btn" })
                        }
                        else
                        {
                            @Html.ActionLink("Reset", "Create", new { questionTypeId = @Model.QuestionTypeId, subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                            @Html.ActionLink("Cancel", "Index", new { subjectId = ViewBag.Subject.SubjectId }, new { style = "width: 54px", @class = "btn" })
                        }
                    </td>
                </tr>
            }
        }
    </table>
}